#ifndef _SIMPLESTACK_H
#define _SIMPLESTACK_H

template <class T> class simplestack
{
    public:
        simplestack( unsigned long maxsize );
        ~simplestack() { delete [] pbeg; }

        bool empty() const { return ptop <= pbeg; }
        unsigned long size() const;
        const T& top() const;
        void push( const T& t );
        void pop();

    private:
        T *pbeg,
          *pend,
          *ptop;
};

template <class T>
simplestack<T>::simplestack( unsigned long maxsize )
{
    pbeg = new T[maxsize];
    assert( pbeg );
    pend = pbeg + maxsize;
    ptop = pbeg;
}

template <class T>
void simplestack<T>::push( const T& t )
{
    assert ( ptop+1 <= pend );
    *ptop++ = t;
}

template <class T>
const T& simplestack<T>::top() const
{
    assert ( !empty() );
    return *(ptop-1);
}

template <class T>
void simplestack<T>::pop()
{
    assert ( !empty() );
    ptop--;
}

#endif // _SIMPLESTACK_H
